package com.allianz.webapps.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.allianz.frame.utils.ImageUploadUtil;
import com.allianz.frame.utils.PropertiesUtil;
import com.allianz.webapps.https.interfaces.type001.pojo.User;
import com.allianz.webapps.https.interfaces.util.ObjectUtil;
import com.allianz.webapps.https.interfaces.util.SftpUtil;
import com.allianz.webapps.orderspojo.AppBase;
import com.fasterxml.jackson.databind.ObjectMapper;


@Controller
@RequestMapping(value="main")
public class AppSaveChgNBPayController {

	@Autowired
	private ObjectMapper objectMapper;
	@Autowired
	private ObjectUtil objectUtil;
	
	protected final Logger logger = LoggerFactory.getLogger(getClass()); 
	
	/**
	 * 支付接口
	 */
	@RequestMapping(value="appSaveChgNBPay")
	@ResponseBody
	public String appSaveChgNBPay(@RequestParam(value="jsonParam") String jsonParam,HttpServletRequest request,HttpServletResponse response)
			throws Exception{
		//  sftp 转账授权书的上传
		AppBase obj=objectMapper.readValue(jsonParam,AppBase.class);
		String policyRef=obj.getPolicyRef();
		String preprintedNo=obj.getPreprintedNo();
		
		
		
		logger.debug("=====================appBase:"+obj+"=====================preprintedNo："+preprintedNo);
		String path=PropertiesUtil.getResourcePath()+"private/pdf/"+policyRef+"_"+preprintedNo+"/"+"signed/";
		logger.debug("=====================源文件路劲:"+path);
		boolean flag=SftpUtil.sftpUploadPdf(obj.getPolicyRef(), path,2);
		logger.debug("=====================sftp上传结果:"+flag);
			
//------------------------------第三次影像上传
		String ip=ImageUploadUtil.getIP(request);
		
		ImageUploadUtil.imageUploadMethod(policyRef, preprintedNo, "P", ip,null);
		
		
		
		
		
		User user=(User)request.getSession().getAttribute("username");
		obj.setUser(user);
		String body=objectUtil.requestParam(obj, "app.saveChgNBPaymentMethod");
		return body;
	}

}
